package com.sikao.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.SellerOrderBean;
import com.sikao.app.utils.TimeUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/8/23.
 */
public class SellerOrderAdapter extends BaseAdapter {

	private Context context;
	private List<SellerOrderBean.ResBean.ListBean> beans;

	public SellerOrderAdapter(Context context, List<SellerOrderBean.ResBean.ListBean> beans) {
		this.context = context;
		this.beans = beans;
	}

	@Override
	public int getCount() {
		return beans.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		ViewHolder holder;
		if (convertView == null) {
			view = View.inflate(context, R.layout.buyer_order_list_item, null);
			holder = new ViewHolder(view);
			view.setTag(holder);
		} else {
			view = convertView;
			holder = (ViewHolder) view.getTag();
		}
		holder.ordernumbertv.setText(beans.get(position).getId());
		holder.nametv.setText(beans.get(position).getTitle());
		holder.timetv.setText(TimeUtil.timeStampToTime(beans.get(position).getAdd_time(),TimeUtil.fotmatString2));
		holder.pricetv.setText(beans.get(position).getPrice());
		holder.priceunittv.setText("元/"+beans.get(position).getUnit());
		holder.quantitytv.setText("数量"+beans.get(position).getNumber()+beans.get(position).getUnit());
		holder.deliveryplacetv.setText(beans.get(position).getDelivery_area());
		holder.deliverymodetv.setText(beans.get(position).getDelivery_type_str());
		holder.totalpricetv.setText(beans.get(position).getTotal_price());
		if (!beans.get(position).getException_status().equals("0")) {
			//取消
			if (beans.get(position).getException_status().equals("1")) {
				holder.orderstatustv.setText("订单已取消");
			}
			//过期
			if (beans.get(position).getException_status().equals("2")) {
				holder.orderstatustv.setText("订单已过期");
			}
			//冻结
			if (beans.get(position).getException_status().equals("3")) {
				holder.orderstatustv.setText("订单冻结中");
			}
			//仲裁中
			if (beans.get(position).getException_status().equals("4") && beans.get(position).getIs_end().equals("0")) {
				holder.orderstatustv.setText("订单仲裁中");
			}
			//仲裁后
			if (beans.get(position).getException_status().equals("4") && beans.get(position).getIs_end().equals("1")) {
				holder.orderstatustv.setText("订单仲裁结束");
			}
		} else {
			switch (beans.get(position).getStatus()) {
				case "0":
					holder.orderstatustv.setText("等待确认订单");
					break;
				case "1":
					holder.orderstatustv.setText("等待买家付首款");
					break;
				case "2":
					holder.orderstatustv.setText("进行备货");
					break;
				case "3":
					holder.orderstatustv.setText("等待买家付中期款");
					break;
				case "4":
						holder.orderstatustv.setText("确认验收报告");
					break;
				case "5":
					holder.orderstatustv.setText("等待买家验收发票");
					break;
				case "6":
					holder.orderstatustv.setText("等待买家付尾款");
					break;
				case "7":
					if (!beans.get(position).getIs_comment().equals("1")) {
						holder.orderstatustv.setText("等待买家评价");
					} else {
						holder.orderstatustv.setText("已结束");
					}
					break;
				default:
					break;
			}
		}
		return view;
	}

	public class ViewHolder {
		public final TextView ordernumbertv;
		public final TextView orderstatustv;
		public final TextView nametv;
		public final TextView timetv;
		public final TextView pricetv;
		public final TextView priceunittv;
		public final TextView quantitytv;
		public final TextView deliveryplacetv;
		public final TextView deliverymodetv;
		public final TextView totalpricetv;
		public final View root;

		public ViewHolder(View root) {
			ordernumbertv = (TextView) root.findViewById(R.id.order_number_tv);
			orderstatustv = (TextView) root.findViewById(R.id.order_status_tv);
			nametv = (TextView) root.findViewById(R.id.name_tv);
			timetv = (TextView) root.findViewById(R.id.time_tv);
			pricetv = (TextView) root.findViewById(R.id.price_tv);
			priceunittv = (TextView) root.findViewById(R.id.price_unit_tv);
			quantitytv = (TextView) root.findViewById(R.id.quantity_tv);
			deliveryplacetv = (TextView) root.findViewById(R.id.delivery_place_tv);
			deliverymodetv = (TextView) root.findViewById(R.id.delivery_mode_tv);
			totalpricetv = (TextView) root.findViewById(R.id.total_price_tv);
			this.root = root;
		}
	}
}
